import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:get/get.dart';
import 'package:getx_learn/app/common/widgets/widgets.dart';

import '../controllers/deep_link_demo_controller.dart';

class DeepLinkDemoView extends GetView<DeepLinkDemoController> {
  const DeepLinkDemoView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(context: context, title: "DeepLinkDemoView"),
      body: ListView(
        children: [
          const Text("""
          android 的配置
          android/app/src/main/AndroidManifest.xml
          <activity
          ... >
          ...
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!--这里是定义协议，类似 http、https等，这里定义的是 hzhgetx，也就是通过这个协议访问的，都可以跳转到当前页面-->
                <data android:scheme="hzhgetx" />
            </intent-filter>
          </activity>
          """),
          Divider(),
          ListTile(
            title: Text("打开浏览器"),
            subtitle: Text("打开后粘贴的内容放到w3c的运行网站，生成网页"),
            onTap: () async {
              // 复制内容
              var content = """
              <!DOCTYPE html>
              <html>
              <head>
              <meta charset="utf-8">
              <title>菜鸟教程(runoob.com)</title>
              </head>
              <body>
              
              <a href="hzhgetx://www.hzh.com/index">hzhgetx://www.hzh.com/index</a>
              <a href="hzhgetx://www.hzh.com/utils">hzhgetx://www.hzh.com/utils</a>
              
              </body>
              </html>
              """;

              Clipboard.setData(ClipboardData(text: content));
              await Get.snackbar("复制提醒", "${content}已复制",
                  duration: Duration(milliseconds: 1000),
                  snackbarStatus: (status) {
                if (status == SnackbarStatus.CLOSED) {
                  // 跳转浏览器
                  final intent = AndroidIntent(
                    action: 'action_view',
                    data: Uri.encodeFull(
                        'https://www.runoob.com/try/try.php?filename=tryhtml_intro'),
                    package: 'com.android.chrome',
                  );
                  intent.launch();
                }
              });
            },
          ),
        ],
      ),
    );
  }
}
